﻿''' <summary>
''' The module that decides the type of statement entered from the code itself.
''' </summary>
''' <remarks></remarks>
Module Executor

    ''' <summary>
    ''' Processes the line of code to see ehat type it is then takes all the actions needed to carry it out.
    ''' </summary>
    ''' <param name="Instruction">The instruction/line of code to process.</param>
    ''' <remarks></remarks>
    Sub Process(ByVal Instruction As String)

        Instruction = Instruction.Trim()

        If Instruction Like "//*" Then
        ElseIf Instruction = "" Or Instruction = " " Then
        ElseIf Instruction.Contains("[") And Instruction.Contains("]") Then
            Statements.StmtProcess(Instruction)
        ElseIf Instruction Like "* = *" = True And Instruction Like "* == *" = False Then
            Basic.AssignVal(Instruction)

        ElseIf Instruction Like "*(*)*" Or Instruction Like "*()*" Then

            Dim readwords As String = Instruction

            If readwords.Contains("Console.ReadLine()") Then
                Basic.AssignVal(Instruction)
            ElseIf readwords.Contains("ReadAllText") Then
                Basic.AssignVal(Instruction)
            ElseIf readwords.Contains("Console.ReadKey()") Then
                Console.ReadKey()
            ElseIf readwords.Contains("Console.Clear()") Then
                Console.Clear()
            Else
                Dim words As String = Instruction
                Dim split() As String = {"", ""}

                Dim i As Integer = -1
                Dim len As Integer = words.Length - 1
                Dim arr As String = ""
                Dim ch As String = ""
                Dim ins As Boolean = False

                Do Until i = len
                    i = i + 1
                    ch = words.Chars(i)

                    If ch = "'" Then
                        If ins = False Then
                            ins = True
                        ElseIf ins = True Then
                            ins = False
                        End If
                    End If

                    If ch = "." And ins = True Then
                        arr = arr & ch
                    ElseIf ch = "." And ins = False Then
                        arr = arr.Trim()
                        split(0) = arr
                        arr = ""
                    Else
                        arr = arr & ch
                    End If

                    If i = len Then
                        arr = arr.Trim()
                        split(1) = arr
                        arr = ""
                    End If
                Loop

                If split(0) = "Console" Then
                    Basic.ConsoleP(split(1))
                ElseIf split(0) = "FileSystem" Then
                    FileSys.ProcessFS(split(1))
                Else
                    Relations.Input(Instruction)
                End If
            End If
        ElseIf Instruction Like "string *" Or Instruction Like "int *" Or _
               Instruction Like "double *" Or Instruction Like "bool *" Then

            Basic.NewVar(Instruction)

        ElseIf Instruction Like "return *" Or Instruction Like "Return *" Then
            Relations.RetVal(Instruction)
        End If
    End Sub


End Module
